/** */
package co.com.umobile.service.impl;

import java.util.HashMap;

import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;
import android.content.Context;
import co.com.umobile.application.GlobalState;
import co.com.umobile.common.util.ServicesCodes;
import co.com.umobile.entity.updates.UpdateEntity;
import co.com.umobile.service.SubjectSyncService;
import co.com.umobile.service.UpdateServices;

/**
 * @author sergiogranada
 * 
 */
public class UpdateServicesImpl implements UpdateServices {

	/*
	 * (non-Javadoc)
	 * 
	 * @see co.com.umobile.service.UpdateServices#isDataAvailableForOption(int[])
	 */
	public HashMap<Integer, Boolean> isDataAvailableForOption(int[] services) {
		// TODO Auto-generated method stub
		return null;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see co.com.umobile.service.UpdateServices#getUpdateEntity(java.lang.String, java.lang.String, int)
	 */
	public UpdateEntity getUpdateEntity(String userName, String company, int serviceCode) {
		// TODO Auto-generated method stub
		return null;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see co.com.umobile.service.UpdateServices#isAnyServiceRunning(android.content.Context,
	 * co.com.umobile.application.GlobalState)
	 */
	public boolean isAnyServiceRunning(Context context, GlobalState globalState) {
		ActivityManager manager = (ActivityManager) context.getSystemService(Activity.ACTIVITY_SERVICE);
		for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
			String serviceClassName = service.service.getClassName();

			String[] classNames = { SubjectSyncService.class.getName() };

			for (String className : classNames) {
				if (className.equals(serviceClassName)) {
					return true;
				}
			}

		}

		if (globalState != null && globalState.getHandlerByService() != null) {

			Integer[] serviceCodes = ServicesCodes.getServices();

			for (Integer service : serviceCodes) {

				if (globalState.getHandlerByService().containsKey(service)) {
					return true;
				}

			}
		}

		return false;
	}

}
